package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.article.entity.ApArticle;
import com.heima.article.entity.ApAuthor;
import com.heima.article.service.ApArticleService;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.media.dtos.WmNewsResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ApArticleController {

    @Autowired
    private ApArticleService apArticleService;




    /**
     * 自媒体文章审核通过以后，feign调用，创建article
     * */
    @PostMapping("/api/v1/article/save")
    public Long createArticle(@RequestBody WmNewsResultDTO dto){
        return apArticleService.createArticle(dto);
    }

    /**
     * 加载首页文章
     * @return
     */
    @PostMapping("/api/v1/article/load")
    public ResponseResult<List<ArticleDto>> load(@RequestBody ArticleHomeDto dto) {
        List<ApArticle> articleDtoList = apArticleService.load(dto,1);
        return ResponseResult.ok(articleDtoList);
    }
    /**
     * 加载更多
     * @return
     */
    @PostMapping("/api/v1/article/loadmore")
    public ResponseResult<List<ArticleDto>> loadMore(@RequestBody ArticleHomeDto dto) {
        List<ApArticle> articleDtoList =  apArticleService.load(dto,1);
        return ResponseResult.ok(articleDtoList);
    }
    /**
     * 加载最新
     * @return
     */
    @PostMapping("/api/v1/article/loadnew")
    public ResponseResult<List<ArticleDto>> loadNew(@RequestBody ArticleHomeDto dto) {
        List<ApArticle> articleDtoList = apArticleService.load(dto,2);
        return ResponseResult.ok(articleDtoList);
    }

    /**
     * feign借口调用分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/api/v1/article/findByPage")
    public List<ArticleDto> findByPage(@RequestParam("page") int page,
                                       @RequestParam("size") int size){
        return apArticleService.findByPage(page,size);

    }
    /**
     * feign借口调用根据id查询详情
     */
    @GetMapping("/api/v1/article/findById/{id}")
   public ArticleDto findById(@PathVariable("id") Long articleId){
        return apArticleService.findById(articleId);
    }

}
